

/***********************************************************
 *     momodel.c
 *
 *     该文件由MWorks.Sysplorer嵌入式代码生成器自动生成。
 *
 *     模型名称：SECModel1
 *     生成时间：2023-11-13 10:05:08
 *
 *     苏州同元软控信息技术有限公司
 *              2005-2023
 *
 ***********************************************************/

#include "string.h"

#include "math.h"

#include "momodel.h"

#include "momodel_extern_inc.h"

#define secmodel1MwRSize 1

#define secmodel1MwISize 2

#define secmodel1InteStepSize 0.002

#define _TIME modelData._Time

#define secmodel1MwR modelData.m_real

#define secmodel1MwI modelData.m_int

#define secmodel1MaxInt32T ((MoInt32)(2147483647))

#define secmodel1MinInt32T ((MoInt32)(-2147483647 - 1))

#define mwSecmodel1IsModelInit() modelData.m_modelInit

#define mwSecmodel1SetModelInit(val) modelData.m_modelInit = (val)

#define mwSecmodel1IsModelInitialed() modelData.m_modelInitEnd

#define mwSecmodel1SetModelInitialed(val) modelData.m_modelInitEnd = (val)

#define mwSecmodel1GetTime() _TIME

#define mwSecmodel1SetTime(val) _TIME = (val)

#define secmodel1GetStepSizeM() modelData.m_stepSize

#define mwSecmodel1GetStepCount() modelData.m_stepCount

#define mwSecmodel1IncStepCount() ++modelData.m_stepCount

#define mwSecmodel1GetStartTime() modelData.m_startTime

#define mwSecmodel1SetStartTime(val) modelData.m_startTime = (val)

struct MultiSecmodel1a_canu_receiveu_3
{
  MoInt out;
  MoInt buf;
};

typedef struct
{
  MoInt _ECG2001_k;
} secmodel1Constant41;

typedef struct
{
  MoInt out;
} secm7Canu_modeu_initu_user2u_13;

typedef struct
{
  secmodel1Constant41 constant4;
  secm7Canu_modeu_initu_user2u_13 can_mode_init_user2_1;
} secmodel1Secmodel1;

struct secmodel1SolverModelData
{
  MoDouble m_stepSize;
  MoSize m_stepCount;
  MoDouble m_startTime;
  MoDouble _Time;
  secmodel1Secmodel1 m_vars;

  MoBool m_modelInit;
  MoBool m_modelInitEnd;
};

MoInt tsjw;

MoInt tbs2;

MoInt tbs1;

MoInt mode;

MoInt msg;

MoInt len;

MoInt successorfail;

MoInt sendflag;

MoInt successorfail2;

MoInt outbuf;

MoInt recflag;

struct secmodel1SolverModelData modelData;

enum mwStatus mwSecmodel1DoPreUpdate(void);

MoInt CAN_Mode_Init_user(MoInt, MoInt, MoInt, MoInt, MoInt);

MoInt Can_Receive_Msg_user(MoInt *, MoInt);

MoInt Can_Send_Msg_user(MoInt, MoInt, MoInt);

MoInt SECModel1a_canu_modeu_initu_us1(MoInt tsjw, MoInt tbs2, MoInt tbs1, MoInt brp, MoInt mode);

struct MultiSecmodel1a_canu_receiveu_3 SECModel1a_canu_receiveu_msgu_2(MoInt rec_flag);

MoInt SECModel1a_canu_sendu_msgu_use5(MoInt msg, MoInt len, MoInt send_flag);

void mwSecmodel1SampleDataInit(void);

enum mwStatus mwSecmodel1DoModelVarInit(void)
{

  MoInt intInitArray[1] = {4};

  modelData.m_vars.constant4._ECG2001_k = intInitArray[0];

  tsjw = 0;

  tbs2 = 0;

  tbs1 = 0;

  mode = 0;

  msg = 0;

  len = 0;

  successorfail = 0;

  sendflag = 0;

  successorfail2 = 0;

  outbuf = 0;

  recflag = 0;

  /* Inital sample data*/
  mwSecmodel1SampleDataInit();
  /* Depending parameter values */

  /* Fixed equations */

  /* Initial equations */

  (void)mwSecmodel1DoPreUpdate();

  return mwStatusOk;
} /*mwSecmodel1DoModelVarInit*/

enum mwStatus mwSecmodel1DoPreUpdate(void)
{ /* No pre variables, do nothing */
  return mwStatusOk;
}

enum mwStatus SECModel1_DoStep(void)
{
  if (!mwSecmodel1IsModelInit() && !mwSecmodel1IsModelInitialed())
  {
    mwSecmodel1IncStepCount();
  }
  mwSecmodel1SetTime(mwSecmodel1GetStartTime() + mwSecmodel1GetStepCount() * secmodel1InteStepSize);

  /* Normal equations */

  /*if (mwSecmodel1IsIntegeratorStep())*/
  {

    modelData.m_vars.can_mode_init_user2_1.out = SECModel1a_canu_modeu_initu_us1(
        tsjw, tbs2, tbs1, modelData.m_vars.constant4._ECG2001_k, mode);

    {
      struct MultiSecmodel1a_canu_receiveu_3 tmpMulti4a_canu_receiveu_msgu_2;

      tmpMulti4a_canu_receiveu_msgu_2 = SECModel1a_canu_receiveu_msgu_2(

          recflag);

      successorfail2 = tmpMulti4a_canu_receiveu_msgu_2.out;

      outbuf = tmpMulti4a_canu_receiveu_msgu_2.buf;
    }

    successorfail = SECModel1a_canu_sendu_msgu_use5(msg, len, sendflag);

    /* Reinit equations */
    /* Update pre variable */
    (void)mwSecmodel1DoPreUpdate();
    /* Update when condition */

    /* Check variable value */
  }

  return mwStatusOk;
} /*mwSecmodel1DoModelCalculate*/

/* SECModel1.can_mode_init_user2.func_CCaller1 */

MoInt SECModel1a_canu_modeu_initu_us1(MoInt tsjw, MoInt tbs2, MoInt tbs1, MoInt brp, MoInt mode)
{

  MoInt out;

  out = 0;

  out = CAN_Mode_Init_user(tsjw, tbs2, tbs1, brp, mode);

  return out;
}

/* SECModel1.can_receive_msg_user1.func_CCaller1 */

struct MultiSecmodel1a_canu_receiveu_3 SECModel1a_canu_receiveu_msgu_2(MoInt rec_flag)
{

  struct MultiSecmodel1a_canu_receiveu_3 resMulti6a_canu_receiveu_msgu_2;

  MoInt out;

  MoInt buf;

  out = 0;

  buf = 0;

  out = Can_Receive_Msg_user(&buf, rec_flag);

  resMulti6a_canu_receiveu_msgu_2.out = out;
  resMulti6a_canu_receiveu_msgu_2.buf = buf;
  return resMulti6a_canu_receiveu_msgu_2;
}

/* SECModel1.can_send_msg_user1.func_CCaller1 */

MoInt SECModel1a_canu_sendu_msgu_use5(MoInt msg, MoInt len, MoInt send_flag)
{

  MoInt out;

  out = 0;

  out = Can_Send_Msg_user(msg, len, send_flag);

  return out;
}

MoDouble mwSecmodel1GetStepSize(void) { return modelData.m_stepSize; }

void mwSecmodel1SetStepSize(MoDouble val) { modelData.m_stepSize = val; }

enum mwStatus SECModel1_Init(void)
{
  enum mwStatus stat;

  (void)memset(&modelData, 0, sizeof(struct secmodel1SolverModelData));
  mwSecmodel1SetStepSize(secmodel1InteStepSize);
  mwSecmodel1DoModelVarInit();

  mwSecmodel1SetStepSize(0.0);
  mwSecmodel1SetModelInit(moTrue);
  mwSecmodel1SetTime(0);
  mwSecmodel1SetStartTime(0);
  stat = SECModel1_DoStep();
  if (mwStatusOk == stat)
  {
    mwSecmodel1SetModelInit(moFalse);
    mwSecmodel1SetModelInitialed(moTrue);
    stat = SECModel1_DoStep();
    if (mwStatusOk == stat)
    {
      mwSecmodel1SetStepSize(secmodel1InteStepSize);
      mwSecmodel1SetModelInitialed(moFalse);
    }
  }

  return stat;
}

MoDouble mwSecmodel1GetCurTime(void) { return mwSecmodel1GetTime(); }

void mwSecmodel1SetParamI(MoInt *val) { modelData.m_vars.constant4._ECG2001_k = val[0]; }

void mwSecmodel1SampleDataInit(void) {}
